<?php
// Copyright 2012 @Wondershare
// $Id: test.php 1 2012-11-12����10:54:38Z Administrator $


// require_once ('bootstrap.inc.php');

?>
<script type="text/javascript">

var laozhang = {
	'name' : 'zfl' ,
	'email' : 'zhangfl@wondershare.cn' ,
	'website' : 'weibo.com/904686240'	,
	age: 100,    
	get birth_year() {         
		var d = new Date();         
		var y = d.getFullYear();         
		return ( y - this.age );     
	},     
	set birth_year(year) {         
		var d = new Date();         
		var y = d.getFullYear();         
		this.age = y - year;     
	} 
};

//document.write('<hr />'+ laozhang.birth_year) ;
//laozhang.birth_year = 1999 ;
//document.write('<hr />'+ laozhang.birth_year) ;

function listProperties(obj){
	var newLine = "<br />" ;
	var names = Object.getOwnPropertyNames(obj) ;
	for (var i = 0 ; i < names.length ; i++ ){
		var prop = names[i];         
		document.write(prop + newLine);          
		// 列出对象的属性配置（descriptor）动用getOwnPropertyDescriptor函数。         
		var descriptor = Object.getOwnPropertyDescriptor(obj, prop);         
		for (var attr in descriptor) {             
			document.write("..." + attr + ': ' + descriptor[attr]);             
			document.write(newLine);         
		}         
		document.write(newLine); 
	}
};

var sayHello = function(){
	var hello = "Hello, I'm "+ this.name + ", my email is: " + this.email + ", my website is: " + this.website;
	document.write('<hr />' + hello) ;
};
//sayHello();
//laozhang.hello = sayHello ;
//laozhang.hello();


//Javascript的数据和成员封装很简单。没有类完全是对象操作。纯动态！ 
//Javascript function中的this指针很关键，如果没有的话，那就是局部变量或局部函数。 
//Javascript对象成员函数可以在使用时临时声明，并把一个全局函数直接赋过去就好了。 
//Javascript的成员函数可以在实例上进行修改，也就是说不同实例相同函数名的行为不一定一样。
var person = function(name , email , website){
	this.name = name ;
	this.email = email ;
	this.website = website ;

	this.sayHello = function(){
		var hello = "Hello, I'm "+ this.name + ", my email is: " + this.email + ", my website is: " + this.website;
		document.write('<hr />' + hello) ;
	};
};

//var zfl = new person('zflname' , 'zflemail' , 'zflwebsite');
//var ty = new person('tyname' , 'tyemail' , 'tywebsite');
//zfl.sayHello();
//ty.sayHello();


var Person = Object.create(null);   
Object.defineProperties (     
		Person, {         
			'name'  : {  value: 'Chen Hao'},         
			'email'  : { value : 'haoel@hotmail.com'},         
			'website': { value: 'http://coolshell.cn'}     
		} 
);

Person.sayHello = function(){
	var hello = "Hello, I'm "+ this.name + ", my email is: " + this.email + ", my website is: " + this.website;
	document.write('<hr />' + hello) ;
};

var Student = Object.create(Person) ;
Student.no = '12345678' ;
Student.dept = 'computer' ;
document.write(Student.name + ' ' + Student.email + ' ' + Student.website +'<br>'); 
Student.sayHello();

//重载SayHello方法 
Student.sayHello = function (person) {     
	var hello = "<p>Hello, I am "+ this.name  + ", <br>" + "my email is: " + this.email + ", <br>" +   "my website is: " + this.website 
					+ ", <br>" + "my student no is: " + this. no + ", <br>" + "my departent is: " + this. dept;    
	document.write(hello + '<br>'); 
}
Student.sayHello();
listProperties(Student);























</script>


